package com.hex.ds.hdrs.cron.converter;

import com.hex.ds.hdrs.common.constant.Const;
import com.hex.ds.hdrs.common.utils.BaseUtil;
import com.hex.ds.hdrs.common.utils.HdrsDateUtil;
import com.hex.ds.hdrs.cron.dto.CronTaskDefDto;
import com.hex.ds.hdrs.cron.dto.CronTaskExportDto;
import com.hex.ds.hdrs.cron.dto.CronTaskImportDto;
import com.hex.ds.hdrs.cron.po.CronTaskDef;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(componentModel = "spring", imports = {BaseUtil.class, HdrsDateUtil.class})
public interface ICronTaskDefConverter {

    @Mapping(target = "appCode", source = "appCode")
    @Mapping(target = "batchTag", source = "batchTag")
    CronTaskDefDto toCronTaskDefDto(CronTaskImportDto cronTaskImportDto, String batchTag, String appCode);

    @Mapping(target = "pkId", expression = "java(BaseUtil.getPkId())")
    @Mapping(target = "crtTs", expression = "java(HdrsDateUtil.getCurrentTime())")
    @Mapping(target = "crtUser", expression = "java(BaseUtil.getUserId())")
    @Mapping(target = "upTs", expression = "java(HdrsDateUtil.getCurrentTime())")
    @Mapping(target = "upUser", expression = "java(BaseUtil.getUserId())")
    @Mapping(target = "taskStatus", constant = Const.UNPUBLISHED)
    CronTaskDef toCronTaskDefForAdd(CronTaskDefDto cronTaskDefDto);

    @Mapping(target = "upTs", expression = "java(HdrsDateUtil.getCurrentTime())")
    @Mapping(target = "upUser", expression = "java(BaseUtil.getUserId())")
    CronTaskDef toCronTaskDefForUpdate(CronTaskDefDto cronTaskDefDto);

    CronTaskDef toCronTaskDefQuery(CronTaskDefDto cronTaskDefDto);

    List<CronTaskExportDto> toCronTaskExportDtoList(List<CronTaskDef> cronTaskDefList);
}
